package cq.zhcqk.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dou361.dialogui.DialogUIUtils;
import com.tencent.smtt.sdk.DownloadListener;

import cq.zhcqk.R;
import cq.zhcqk.base.BaseActivity;
import cq.zhcqk.util.Common;
import cq.zhcqk.util.WebViewHeader;
import cq.zhcqk.util.x5.X5WebView;

/**
 * Created by zhangle on 2018/3/22.
 */
public class GzyyListDetailActivity extends BaseActivity implements View.OnClickListener{
    private X5WebView tc_webview;
    private Context context;
    private String id;
    private String departId;
    @Override
    protected void initView() {
        setContentView(R.layout.activity_gzyy_list_detail);
        tc_webview = (X5WebView) findViewById(R.id.tc_webview);
        context = this;
        id = getIntent().getStringExtra("id");
        departId = getIntent().getStringExtra("departId");
    }

    @Override
    protected void initData() {
        webSet();
        WebViewHeader.setHeaderAndLoadX5(tc_webview, Common.URL+"/api/work/workinfo/?workId="+departId);
        initBack();
    }

    private void initBack(){
        ImageView back = (ImageView) findViewById(R.id.header_back);
        TextView title = (TextView) findViewById(R.id.header_text);
        title.setText("工作办理");
        back.setOnClickListener(this);
    }

    public void webSet(){
        if(tc_webview != null)
        {
            com.tencent.smtt.sdk.WebSettings settings = tc_webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setBuiltInZoomControls(true);
            settings.setLoadWithOverviewMode(true);
            settings.setUseWideViewPort(true);
            settings.setDatabaseEnabled(true);
            settings.setBuiltInZoomControls(false);
            settings.setSupportZoom(false);
            settings.setDisplayZoomControls(false);
            tc_webview.setDownloadListener(new MyWebViewDownLoadListener());
            tc_webview.setWebViewClient(new com.tencent.smtt.sdk.WebViewClient()
            {
                @Override
                public void onPageFinished(com.tencent.smtt.sdk.WebView webView, String s) {
                    super.onPageFinished(webView, s);
//                    DialogUIUtils.dismiss(buildBean);
                }

                @Override
                public void onPageStarted(com.tencent.smtt.sdk.WebView webView, String s, Bitmap bitmap) {
                    super.onPageStarted(webView, s, bitmap);
//                    buildBean.show();
                }


            });
        }
    }
    private class MyWebViewDownLoadListener implements DownloadListener {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
//            DialogUIUtils.dismiss(buildBean);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.header_back:
                finish();
                break;
        }
    }
}
